#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct Node
{
	long long id,val;
}a[4000005];
struct Node2
{
	long long id,v;
	bool operator <(const Node2 &x)const
	{
		return a[v].val<a[x.v].val;
	}
};
long long n,k,x,t,cnt=0,cnt2=0,ans=1145141919810,vis[4000005];
priority_queue<Node2> q;
bool cmp(Node x,Node y)
{
	return x.val<y.val;
}
int main()
{
	freopen("contest.in","r",stdin);
	freopen("contest.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(long long i=1;i<=n;i++)
	{
		cin>>k;
		for(long long j=1;j<=k;j++)
		{
			cin>>x;
			a[++cnt].id=i;
			a[cnt].val=x;
		}
	}
	sort(a+1,a+1+cnt,cmp);
	for(long long i=cnt;i>=1;i--)
	{
		if(!vis[a[i].id])
		{
			cnt2++;	
			if(cnt2==n)
			{
				t=i;
				break;
			}
		}
		vis[a[i].id]=i;
		q.push(Node2{a[i].id,i});		
	}
	for(long long i=t;i>=1;i--)
	{
		vis[a[i].id]=i;
		q.push(Node2{a[i].id,i});	
		while(!q.empty()&&vis[q.top().id]!=q.top().v)
		{
			q.pop();
		}
		ans=min(ans,a[q.top().v].val-a[i].val);
	}
	cout<<ans<<endl;
	return 0;
}
